package sebastiankerckhof.scene.material;

import sebastiankerckhof.math.Color3f;
import sebastiankerckhof.math.Vector3f;
import sebastiankerckhof.render.raytrace.Ray;

public class DiffuseMaterial extends AbstractMaterial{
	public DiffuseMaterial(Color3f color) {
		super(color);
	}
	
	@Override
	public Color3f getShade(Color3f t, Color3f cl, Vector3f l, Vector3f n, Ray r) {
				
				Color3f result;
				if(t != null)
					result = t;
				else 
					result = color;
				
				float dot = l.dotProduct(n); //l.n
				dot = Math.max(0, -dot); //max(0,l.n)
				
				
				result = result.multiply(cl).scale(dot); //kd.I.max(0,l.n)
				
				return result.clamp(); //TODO: need for clamp here?
		
	}
}
